<script>
import md5 from "js-md5";
export default {
    onLaunch() {
        // 检查登录态是否过期
        wx.checkSession({
            success() {},
            fail() {
                wx.login({
                    success(res) {
                        if (res.code) {
                            let appid = "wxac10e0b6b389fe20";
                            let secretKey = "66d9a3240d3461ad07df52ccbc8da2fc";
                            let code = res.code;
                            const sign = md5(
                                `appid=${appid}&code=${code}${secretKey}`
                            ).toUpperCase();
                            let data = {
                                appid,
                                code,
                                sign
                            };
                            wx.request({
                                url:
                                    "https://miniapp-api-test.yestae.com/api/MN004",
                                data,
                                header: {
                                    "content-type":
                                        "application/x-www-form-urlencoded"
                                },
                                method: "POST",
                                success: function(res) {}
                            });
                        } else {
                            console.log("登录失败！" + res.errMsg);
                        }
                    }
                });
            }
        });
    }
};
</script>
